package com.keep.log;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
@Slf4j
public class aopLog {

    @Pointcut("execution(public * com.keep.service.*.*(..))")
    public void log(){

    }

    @Before("log()")
    public void beForeLog(JoinPoint joinPoint){
        Object[] args = joinPoint.getArgs();
        Signature signature = joinPoint.getSignature();
        log.info("方法名为{}","参数为{}",signature,args);
    }

    @AfterReturning(pointcut = "log()",returning = "result")
    public void afterReturningLog(Object result){
        log.info("返回值为{}", JSONObject.toJSONString(result));
    }
}
